package ken.app.adapter;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import ken.app.bean.QueryPersonCouponBean;
import ken.app.bean.TreeSingleBean;
import com.she.olympic.R;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.AnimationDrawable;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.she.component.adapter.GenView;
import com.she.component.adapter.GeneralAdapter;
import com.she.component.adapter.iface.IGenView;
import com.she.olympic.TreeActivity;

public class QueryPersonCouponAdapter extends GeneralAdapter {
	
	static ArrayList<QueryPersonCouponBean> mDataList;
	static Handler mhandler;
	static GenSelectAllListItemView mGenSelectAllView = new GenSelectAllListItemView();
	
	public QueryPersonCouponAdapter(Context context, List<?> dataList ,Handler handler) {
		super(context, mGenSelectAllView);
		mDataList = (ArrayList<QueryPersonCouponBean>) dataList;
		mhandler = handler;
		this.setData(mDataList);
	}
			
	public static class GenSelectAllListItemView extends GenView{
		LayoutInflater inflater;
		
		@Override
		protected View genBody(Context context, View convertView,
				final Object element, final int position) {
						
			if (inflater == null) {
				inflater = LayoutInflater.from(context);
			}
			final ViewHolder holder;
			if (convertView != null	&& convertView.getTag() instanceof ViewHolder) 
			{
				holder = (ViewHolder) convertView.getTag();
			} else 
			{
				convertView = inflater.inflate(R.layout.person_coupon_row, null);
				holder = new ViewHolder();
				holder.coupon_gift_name = (TextView) convertView.findViewById(R.id.coupon_gift_name);
				holder.coupon_date = (TextView) convertView.findViewById(R.id.coupon_date);
				convertView.setTag(holder);
			}
			String temp = ((QueryPersonCouponBean) element).getGiftName();
			if (temp.length() > 8) {
				holder.coupon_gift_name.setText(temp.substring(0, 8)+"...");
			}else{
				holder.coupon_gift_name.setText(temp);
			}
			temp = null;
			
			Date date = new Date(((QueryPersonCouponBean) element).getDate() * 1000L);
			DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			holder.coupon_date.setText(dateFormat.format(date));

			return convertView;
		}
		
		private class ViewHolder {
			TextView coupon_gift_name;
			TextView coupon_date;
		}
	}
}
